package com.hjq.permissions.demo;

import android.Manifest;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
import android.view.WindowManager;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.mine.bean.PermissionBean;
import com.mine.listener.PermissionChangeListener;
import com.mine.ui.PermissionFragment;

import java.util.ArrayList;
import java.util.List;

public final class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_main);
        requestPermissionApp();
    }

    private void requestPermissionApp() {
        List<PermissionBean> list = new ArrayList<>();
        list.add(new PermissionBean(com.mine.xpermission.R.mipmap.icon_permission_setting, Settings.ACTION_MANAGE_WRITE_SETTINGS, "系统设置", "设置屏幕亮度"));
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
            list.add(new PermissionBean(com.mine.xpermission.R.mipmap.icon_permission_file, Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION, "文件管理", "文件读写功能"));
        }
        list.add(new PermissionBean(com.mine.xpermission.R.mipmap.icon_permission_float, Settings.ACTION_MANAGE_OVERLAY_PERMISSION, "悬浮窗", "悬浮窗顶部显示"));
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
            list.add(new PermissionBean(com.mine.xpermission.R.mipmap.icon_permission_music, android.Manifest.permission.READ_MEDIA_AUDIO, "音乐与音频", "播放设备音乐"));
            list.add(new PermissionBean(com.mine.xpermission.R.mipmap.icon_permission_image, android.Manifest.permission.READ_MEDIA_IMAGES, "照片查看", "播放设备图片"));
            list.add(new PermissionBean(com.mine.xpermission.R.mipmap.icon_permission_video, android.Manifest.permission.READ_MEDIA_VIDEO, "视频查看", "播放设备视频"));
        } else {
            list.add(new PermissionBean(com.mine.xpermission.R.mipmap.icon_permission_file, android.Manifest.permission.READ_EXTERNAL_STORAGE, "文件读取", "获取设备文件列表"));
            list.add(new PermissionBean(com.mine.xpermission.R.mipmap.icon_permission_file, Manifest.permission.WRITE_EXTERNAL_STORAGE, "文件写入", "创建新的文件"));
        }
//        boolean isComplete = PermissionManager.getInstance(MainActivity.this).checkAllPermissionComplete(list);
//        if (isComplete) {
//            getDefaultSettingInfo();
//            return;
//        }
        PermissionFragment permissionFragment = new PermissionFragment();
        permissionFragment.setPermissionList(list,"我需要");
        permissionFragment.setBoardRoot(false);
        permissionFragment.setOnCallBackListener(new PermissionChangeListener() {
            @Override
            public void onClickComplete() {
                getDefaultSettingInfo();
            }
        });
        permissionFragment.show(getSupportFragmentManager(), "PermissionFragment");
    }

    private void getDefaultSettingInfo() {
        Toast.makeText(MainActivity.this, "权限请求完成", Toast.LENGTH_SHORT).show();
//        finish();
    }
}